# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms.dim import jms_dim__dim_sys_network_detail_dt
# from jms.ods import jms_ods__tab_ops_load_calibration_free, jms_ods__tab_barscan_loading, \
#     jms_ods__tab_barscan_other, jms_ods__yl_tmsnew_tms_shipment_stop, jms_ods__yl_tmsnew_branch_shipment_stop
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.tab.dwd_tab_barscan_other_base_dt import jms_dwd__dwd_tab_barscan_other_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dim.dim_tab_ops_load_calibration_free_base import jms_dim__dim_tab_ops_load_calibration_free_base

jms_dm__dm_cn_load_after_departure_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_cn_load_after_departure_detail_dt',
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    execution_timeout=timedelta(minutes=15),
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_cn_load_after_departure_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_cn_load_after_departure_detail_dt/execute.sql',
    driver_memory='4G',
    driver_cores=2,
    executor_cores=2,
    executor_memory='4G',
    num_executors=5,
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        #'spark.dynamicAllocation.maxExecutors': 20,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors': 10,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '2G',  # 堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict',
        'spark.hadoop.hive.exec.dynamic.partition': 'true'

    },
    yarn_queue='pro',
)
jms_dm__dm_cn_load_after_departure_detail_dt << [
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_tab_barscan_other_base_dt,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
    jms_dim__dim_tab_ops_load_calibration_free_base,
    jms_dim__dim_sys_network_detail_dt
]
